"""
plotwindow.py --

This file implements the BatSim's plotting window.

Date of creation: 2010-15-11

Copyright
Julian David Colorado, jd.colorado@upm.es
Universidad Politecnica de Madrid

See the file "license.terms" for information on usage and redistribution of this file, and for a
DISCLAIMER OF ALL WARRANTIES.
"""

import wx
from numpy import *
#import wx.lib.plot as plot
import wx.lib.plot

class PlotWindow(wx.Frame):
	"""Wind0 1.30801988642ow to plot data."""
	def __init__(self, parent, id, title, variable, data, xlabel, ylabel, xmax, ymin, ymax, xpos, ypos):
		"""Creates the main frame and the plot window."""
		print xmax, ymin, ymax, xpos, ypos,
		wx.Frame.__init__(self, parent, id, title, wx.Point(xpos,ypos), wx.Size(500, 300))
		self.plotwindow = wx.lib.plot.PlotCanvas( self )
		line = wx.lib.plot.PolyLine(data, legend=' ', colour='red', width=2)
		self.gc = wx.lib.plot.PlotGraphics( [line], variable, xlabel, ylabel)
		self.plotwindow.Draw(self.gc,  xAxis= ( 0, (float)(xmax) ), yAxis= ( (float)(ymin),(float)(ymax) ))
		self.Show(True)

def CreatePlotData( object, pos1plotdata, pos2plotdata, vel1plotdata, vel2plotdata, uplotdata, poslimits, vellimits, ulimits ):
	""" Create data for plot windows"""
	list_jump =10
	radstodeg = (180/pi)
	#Getting the position a velocity limits
	poslimits.append( object.system.X[0,:].min())
	poslimits.append( object.system.X[0,:].max())
	poslimits.append( object.system.X[1,:].min())
	poslimits.append( object.system.X[1,:].max())

	vellimits.append( object.system.X[2,:].min())
	vellimits.append( object.system.X[2,:].max())
	vellimits.append( object.system.X[3,:].min())
	vellimits.append( object.system.X[3,:].max())

	ulimits.append( object.system.u[0,:].min())
	ulimits.append( object.system.u[0,:].max())

	if ( object.system.type =="bat"):
		#Getting the list of tuplex data.
		for i in range( size (object.system.timevec)/list_jump ):
			pos1plotdata.append ( ( object.system.timevec[ 0, i*list_jump ], object.system.X[0, i*list_jump]) )
	else:
		#Getting the list of tuplex data.
		for i in range( size (object.system.timevec)/list_jump ):
			pos1plotdata.append ( (object.system.timevec[ 0, i*list_jump ], object.system.X[0, i*list_jump]*radstodeg) )

	for i in range( size (object.system.timevec)/list_jump ):
		pos2plotdata.append ( ( object.system.timevec[ 0, i *list_jump], object.system.X[1, i*list_jump]*radstodeg) )
		vel1plotdata.append ( (object.system.timevec[ 0, i ], object.system.X[2, i*list_jump]*radstodeg) )
		vel2plotdata.append ( (object.system.timevec[ 0, i ], object.system.X[3, i*list_jump]*radstodeg) )
		uplotdata.append ( (object.system.timevec[ 0, i *list_jump], object.system.u[0,i*list_jump]) )



